package com.project.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("user")
public class UserController {

    @RequestMapping("login")
    public String login(String userCode,String userName, String pwd, HttpServletRequest req){
        //服务器产生的验证码
        String code = req.getSession().getAttribute("checkCode").toString();

        //验证码错误
        if(userCode.equalsIgnoreCase(code) == false){
            req.setAttribute("errorInfo","验证码错误");
            return "/login.html";
        }
        //登陆成功
        if("java".equals(userName) && "123".equals(pwd)){
            req.setAttribute("info","登陆成功");
            return "/main.html";
        }
        req.setAttribute("errorInfo","登陆失败");
        return "/login.html";
    }
}
